fs = 1000;         % 采样频率 1kHz
N = 1000;
sigSourceCfg.freqs = [100, 200, 300]; % 复正弦信号的频率（Hz）
sigSourceCfg.gains = [1, 0.8, 0.6]; % 复正弦信号的频率（Hz）
sigSourceCfg.noisePower = 0.1; % 噪声功率
sigSourceCfg.fs = fs; % 采样率（Hz）
sigSourceCfg.numSamples = N; % 样本数
% 生成信号
x = sinu_generator(sigSourceCfg);

windowLength = 200; % 窗长
overlap = 50; % 重叠点数

[Pxx,f] = myWelch(x, fs, windowLength, overlap);

fig = figure('Visible','off');
plot(f, pow2db(Pxx)); % 绘制功率谱（以dB为单位）
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
title('Welch Power Spectrum Estimation');
grid on;
exportgraphics(fig,'test.jpg');
close(fig);

fprintf("sum(Pxx)/win^2: %.2f",sum(Pxx)/windowLength^2);

